import {
  Loading
} from 'element-ui'
import { exportExcel } from '@/utils/index'
import {
  Vue
} from 'vue'

let loadingCount = 0
let loading

// import wewe from '../../views2/ordermenu/orderstatist.vue'
const startLoading = (str) => {
  loading = Loading.service({
    lock: true,
    text: str, // 可以自定义文字
    spinner: 'el-icon-loading', // 自定义加载图标类名
    background: 'rgba(0, 0, 0, 0.7)' // 遮罩层背景色
  })
}

const endLoading = () => {
  loading.close()
}

export const showLoading = (obj) => {
  if (loadingCount === 0) {
    startLoading(obj)
  }
  loadingCount += 1
}

export const hideLoading = () => {
  if (loadingCount <= 0) {
    return
  }
  loadingCount -= 1
  if (loadingCount === 0) {
    endLoading()
  }
}

import request from '@/utils/request'
import axios from 'axios'
// 导出
export function exportpsf(obj, url) { // 导出
  // console.log(JSON.stringify(obj))
  return axios({
    url: '/defi' + url,
    method: 'post',
    responseType: 'arraybuffer',
    // responseType: 'arraybuffer',
    data: JSON.stringify(obj),
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

function setobj(data) {
  for (const key in data) {
    data[key] == '' ? (data[key] = null) : data[key]
    //   data[key] == "0" ? (data[key] = null) : data[key];
    data[key] == '155' ? (data[key] = null) : data[key]
    data[key] == undefined ? (data[key] = null) : data[key]
  }
  return data
}
export function duduxia(obj, url, str) {
  if (obj) {
    obj = setobj(obj)
    exportpsf(obj, url).then(res => {
      exportExcel(res.data, `${str}.xlsx`)
    })
  }
}

